#include <iostream>
#include <vector>

using namespace std;
vector<vector<int>> ans;
vector<int> path;
bool visited[10] = { false };
void dfs(vector<int>& nums)
{
	if (path.size() == nums.size())
	{
		ans.push_back(path);
		return;
	}
	for (int i = 0; i < nums.size(); i++)
	{
		if (visited[i] == false)
		{
			visited[i] = true;
			path.push_back(nums[i]);
			dfs(nums);
			path.pop_back();
			visited[i] = false;
		}
	}
}
vector<vector<int>> permute(vector<int>& nums) 
{
	dfs(nums);
	return ans;
}

int main()
{
	vector<int> v = { 1,2,3 };
	auto ans = permute(v);
	for (int i = 0; i < ans.size(); i++)
	{
		for (int j = 0; j < ans[0].size(); j++)
		{
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}